function ReinitIframe(frame){
	this.iframe = document.getElementById(frame);
	var bHeight = 0;
	var dHeight = 0;
	if(this.iframe != null){
		if(this.iframe.contentWindow.document.body.scrollHeight != null)
		bHeight = this.iframe.contentWindow.document.body.scrollHeight;
		if(this.iframe.contentWindow.document.documentElement.scrollHeight != null)
		dHeight = this.iframe.contentWindow.document.documentElement.scrollHeight;
	}
	var height = Math.max(bHeight, dHeight);
	this.iframe.height = height;
}
function SortTr(content,dates,btn){
	this.content = document.getElementById(content);
	this.trs=this.content.getElementsByTagName('TR');
	this.btn=document.getElementById(btn);
	this.btn.style.cursor = 'pointer';
	this.dir=1;
	this.a = [];
	var reg = /(\d{4})-(\d{1,2})-(\d{1,2})/;
	for(var i=0;i<this.trs.length;i++){
		var time=css.find(dates,this.trs[i])[0];
		var date = new Date();
		var re = reg.exec(time.innerHTML);
		date.setFullYear(re[1]);
		date.setMonth(re[2]-1);
		date.setDate(re[3]);
		date.setHours(0);
		date.setMinutes(0);
		date.setSeconds(0);
		this.a.push({
			node:this.trs[i],
			formatTime:date
		})
	}
	var _this = this;
	this.btn.onclick = function(){
		_this.a.sort(function(a1,a2){
		if(a1.formatTime > a2.formatTime){
			return _this.dir;
		} else if(a1.formatTime < a2.formatTime){
			return -_this.dir;
		} else{
			return 0;
		}
			
		});
		_this.dir = -_this.dir;
		_this.add();
	}
};
SortTr.prototype = {
	add:function(){
		this.content.innerHTML = '';
		var frag = document.createDocumentFragment();
		for(var i=0;i<this.a.length;i++){
			frag.appendChild(this.a[i].node);
			if(i%2==0){
				css.add(this.a[i].node,'alt-row');
			} else{
				css.del(this.a[i].node,'alt-row')
			}
		}
		this.content.appendChild(frag);
	}
};
function SrotStage(content,stage,btn){
	this.content = document.getElementById(content);
	this.trs=this.content.getElementsByTagName('TR');
	this.btn=document.getElementById(btn);
	this.btn.style.cursor = 'pointer';
	this.dir=1;
	this.a = [];
	for(var i=0; i<this.trs.length;i++){
		var stageOrder = css.find(stage,this.trs[i])[0].value;
		this.a.push({
			node:this.trs[i],
			formatTime:stageOrder
		})
	}
	var _this = this;
	this.btn.onclick=function(){
		_this.a.sort(function(a1,a2){
			if(a1.formatTime>a2.formatTime){
				return _this.dir;
			} else if(a1.formatTime<a2.formatTime){
				return -_this.dir;
			} else{
				return 0;
			}
		});
		_this.dir = -_this.dir;
		_this.add();
	}
};
SrotStage.prototype = {
	add:function(){
		this.content.innerHTML = '';
		var frag = document.createDocumentFragment();
		for(var i=0;i<this.a.length;i++){
			frag.appendChild(this.a[i].node);
			if(i%2==0){
				css.add(this.a[i].node,'alt-row');
			} else{
				css.del(this.a[i].node,'alt-row')
			}
		}
		this.content.appendChild(frag);
	}
};
var css={
		has:function(o,n){
			var reg=new RegExp("(^|\\s)" + n + "(\\s|$)");
			if(reg.test(o.className)){
				return true;
			} else {
				return false;
			}
		},
		add:function(o,n){
			if(this.has(o,n)){
				return;
			} else{
				var ao=o.className.split(' ');
				ao.push(n);
				o.className = ao.join(' ');
			}
		},
		del:function(o,n){
			var ao=o.className.split(' ');
			for(var i in ao){
				if(ao[i] == n){
					ao.splice(i,1);
					o.className=ao.join(' ');
					return;
				} 
			}
		},
		find: function(n, e){
			e = e || document;
				if(e.getElementsByClassName){
					return e.getElementsByClassName(n);
				} else if(e.querySelectorAll){
					return e.querySelectorAll("." + n);
				} else{
					var tem = [];
					var nodes=e.getElementsByTagName('*');
					for(var i=0;i<nodes.length;i++){
						if(this.has(nodes[i],n)){
							tem.push(nodes[i]);
						}
					}	
					return tem;
				}
			
		}
	}